package com.yanqu.road.server.cmd.cricket.court;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketMgr;
import com.yanqu.road.server.gameplayer.module.cricket.entity.DbUserCricketBattleLogDetail;
import com.yanqu.road.server.gameplayer.module.cricket.entity.business.CricketGameBusiness;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.*;
import com.yanqu.road.sync.message.SyncResponse;

import java.util.concurrent.CompletableFuture;

@Cmd(code = GameProtocol.S_CRICKET_BATTLE_LOG_DETAIL, desc = "战报详情")
public class CricketBattleLogDetailCmd extends AbstractCommand {

    private long id;

    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CricketBattleLogDetailReqMsg reqMsg = CricketProto.CricketBattleLogDetailReqMsg.parseFrom(packet.getBytes());
        id = reqMsg.getId();
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CricketProto.CricketBattleLogDetailRespMsg.Builder respMsg = CricketProto.CricketBattleLogDetailRespMsg.newBuilder();
        respMsg.setRet(0);
        if (id == 0) {
            respMsg.setRet(GameErrorCode.E_ERROR_PARAMETER);
            player.sendPacket(ClientProtocol.U_CRICKET_BATTLE_LOG_DETAIL, respMsg);
            return;
        }
        if (type == 1) {
            // 上跨服拿
            CricketProto.CricketBattleLogDetailReqMsg.Builder reqMsg = CricketProto.CricketBattleLogDetailReqMsg.newBuilder();
            reqMsg.setId(id);
            reqMsg.setType(type);
            player.sendPacket(Protocol.C_CRICKET_HOT_BATTLE_LOG_DETAIL, reqMsg);
        } else {
            DbUserCricketBattleLogDetail dbUserCricketBattleLogDetail = CricketGameBusiness.getDbUserCricketBattleLogDetail(id);
            if (dbUserCricketBattleLogDetail != null) {
                respMsg.setMatchRound(dbUserCricketBattleLogDetail.getCricketBattleLog());
            } else {
                respMsg.setRet(GameErrorCode.E_CRICKET_BATTLE_LOG_DETAIL_NOT_FOUND);
            }
            player.sendPacket(ClientProtocol.U_CRICKET_BATTLE_LOG_DETAIL, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
